using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using AJAXCore.Data;
using AJAXCore.Models;

namespace AJAXCore.Repositories {
  public class Repository : IRepository {
    private MyDBContext _context;

    public Repository(MyDBContext context) {
      _context = context;
    }


    public IEnumerable<Country> Countries {
      get { return _context.Country.ToList(); }
    }

    public IEnumerable<State> States {
      get { return _context.State.ToList(); }
    }

    public IEnumerable<Member> Members {
      get { return _context.Member.ToList(); }
    }

    public int Count<T>() where T:class{
      switch (typeof(T).Name) {
        case "Member": return _context.Member.Count();
        case "Country": return _context.Country.Count();
        case "State": return _context.State.Count();
      }
      throw new Exception("Invalid type ");
    }
  }
}
